local skill = fk.CreateSkill{
  name = "tea__tengchao&",
}
local U = require "packages/utility/utility"
---@type ViewAsSkillSpec
local tengchao_other = {
  anim_type = "special",
  pattern = ".|.|.|.|.|trick",
  prompt = "#tea__tengchao_other-active",
  mute = true,
  interaction = function(self, player)
    local all_names = Fk:getAllCardNames("t")
    local names = player:getViewAsCardNames("tea__tengchao", all_names, player:getCardIds("he"))
    local source = table.filter(Fk:currentRoom().alive_players, function(p)
      return p:getMark("@tea__tengchao_num") > 0
    end)[1]
    local use_names = table.map(source:getPile("tea__zhuanfu_record"), function(c)
      return Fk:getCardById(c).name
    end)
    names = table.filter(names, function(n)
      return table.contains(use_names, n)
    end)
    if #names > 0 then
      return UI.CardNameBox { choices = names, all_choices = all_names }
    end
  end,
  card_filter = function(self, player, to_select, selected)
    return true
  end,
  view_as = function(self, player, cards)
    local source = table.filter(Fk:currentRoom().alive_players, function(p)
      return p:getMark("@tea__tengchao_num") > 0
    end)[1]
    if not self.interaction.data or #cards <= source:getMark("@tea__tengchao_num") then return end
    local card = Fk:cloneCard(self.interaction.data)
    card.skillName = "tea__tengchao"
    card:addSubcards(cards)
    return card
  end,
  before_use = function(self, player, use)
    local room = player.room
    use.extra_data = {tengchao_use = true}
    local targets = table.filter(room.alive_players, function(p)
      return p:hasSkill("tea__tengchao")
    end)
    if #targets > 0 then
      local target = targets[1]
      room:setPlayerMark(target, "@tea__tengchao_num", #(use.card.subcards or {}))
      room:notifySkillInvoked(player, "tea__tengchao", "special")
      target:broadcastSkillInvoke("tea__tengchao")
    end
  end,
  enabled_at_play = function(self, player)
    local source = table.filter(Fk:currentRoom().alive_players, function(p)
      return p:getMark("@tea__tengchao_num") > 0
    end)
    return player.phase ~= Player.NotActive and #source > 0 and player:usedSkillTimes(skill.name, Player.HistoryTurn) == 0
  end,
  enabled_at_response = function(self, player, response)
    local source = table.filter(Fk:currentRoom().alive_players, function(p)
      return p:getMark("@tea__tengchao_num") > 0
    end)
    return not response and player.phase ~= Player.NotActive and #source > 0 and player:usedSkillTimes(skill.name, Player.HistoryTurn) == 0
  end,
}
skill:addEffect("viewas", tengchao_other)
return skill